/*
 * Copyright [2013-2021], Alibaba Group Holding Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.alibaba.polardbx.optimizer.partition.datatype;

/**
 * @author chenghui.lch
 */
public class PartitionFieldTestUtil {

    protected static final long INIT_HASH_VALUE_1 = 1L;
    protected static final long INIT_HASH_VALUE_2 = 4L;

    public static  long calcHashCodeForKey(PartitionField field) {
        return calcHashCodeForKey(1, new PartitionField[] {field});
    }

    public static  long calcHashCodeForKey(int partCnt, PartitionField[] fields) {
        long[] seeds = new long[2];
        seeds[0] = INIT_HASH_VALUE_1;
        seeds[1] = INIT_HASH_VALUE_2;
        int i = 0;
        do {
            PartitionField field = fields[i];
            field.hash(seeds);
            ++i;
        } while (i < partCnt);
        long outputHashCode = seeds[0];
        return outputHashCode;
    }
}
